<template>
  <view class="container">
    <view class="chart-content">
      <view class="chart-title">数据对比</view>
      <view class="training-stats">
        <view class="stat-item">
          <text class="stat-label">总训练次数</text>
          <view class="stat-value-wrapper">
            <text class="stat-value">{{ shareData.totalCount }}</text>
            <text class="stat-unit">次</text>
          </view>
        </view>
        <view class="stat-item">
          <text class="stat-label">本周训练</text>
          <view class="stat-value-wrapper">
            <text class="stat-prefix">第</text>
            <text class="stat-value">{{ shareData.weekTrainingCount }}</text>
            <text class="stat-unit">次</text>
          </view>
        </view>
      </view>
      <view class="charts">
        <qiun-data-charts
          type="line"
          :opts="opts"
          :chartData="shareData.chartData"
          :canvas2d="true"
          canvasId="compareChart"
        />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      shareData: {},
      opts: {
        color: ["#1890FF", "#91CB74", "#FAC858"],
        padding: [15, 15, 15, 15],
        enableScroll: false,
        legend: {
          show: true,
          position: "top",
          float: "center",
        },
        xAxis: {
          type: "category",
          boundaryGap: true,
        },
        yAxis: {
          splitLine: true,
          axisLine: true,
          scale: true,
          min: 0,
          max: 100,
          interval: 10,
        },
        extra: {
          line: {
            type: "straight",
            width: 2,
            activeType: "hollow",
          },
        },
      },
    };
  },
  
  onLoad(options) {
    if (options.shareData) {
      this.shareData = JSON.parse(decodeURIComponent(options.shareData));
    }
  }
}
</script>

<style lang="scss">
.container {
  padding: 30rpx;
  background: #f5f5f5;
  min-height: 100vh;
}

.chart-content {
  background: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}

.chart-title {
  font-size: 32rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
}

.training-stats {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20rpx;
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 28rpx;
  color: #666;
  margin-bottom: 10rpx;
}

.stat-value-wrapper {
  display: flex;
  align-items: baseline;
}

.stat-value {
  font-size: 32rpx;
  font-weight: bold;
  margin-right: 10rpx;
}

.stat-unit {
  font-size: 28rpx;
  color: #666;
}

.stat-prefix {
  font-size: 28rpx;
  color: #666;
  margin-right: 10rpx;
}

.charts {
  width: 100%;
  height: 300px;
}
</style>